class AddActiveRbac < ActiveRecord::Migration
  def self.up
  say "Creating table 'users' and indexes..."
    ActiveRecord::Base.transaction do
      #say "Create table users.", true
      #create_table(:users) do |t|
      #end

      say "Create table roles.", true
      create_table(:roles) do |t|
        t.column :identifier,         :string,    :limit => 100, :null => false
      end

      say "Add indexes on table 'roles'.", true
      add_index :roles, :identifier

      say "Add relation table roles <---> users", true
      create_table(:roles_users, :id => false) do |t|
        t.column :role_id,            :integer, :null => false
        t.column :user_id,            :integer, :null => false
      end

      say "Add indexes on 'roles_users'", true
      add_index :roles_users, [ :role_id, :user_id ], :unique => true
    end

    say "Create table 'static_permissions'.", true
    create_table(:static_permissions) do |t|
      t.column :identifier,         :string,    :limit => 100, :null => false
    end

    say "Add indexes on table 'static_permissions'.", true
    add_index :static_permissions, :identifier

    say "Add relation table roles <---> static_permissions", true
    create_table(:roles_static_permissions, :id => false) do |t|
      t.column :role_id,              :integer, :null => false
      t.column :static_permission_id, :integer, :null => false
    end
    say "Add indexes on 'roles_static_permissions'", true
  end

  def self.down
  end
end
